package com.znf4.controller.user;

import java.util.ArrayList;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.znf4.entity.ApiCommonResultVo;
import com.znf4.user.bank.entity.UserBank;
import com.znf4.user.bank.server.UserBankServer;

/**
 * 银行卡信息
 */
@RestController
@RequestMapping("/gzh/user/bank")
public class UserBankController {
	
	private static final Logger LOG = LoggerFactory.getLogger(UserAddressController.class);
	
	@Autowired
	private UserBankServer userBankServer ;
	

	/**
	 * 函数功能说明 ： 添加银行卡信息
	 *
	 * @参数： @return
	 * @return String
	 * @throws
	 */
	@RequestMapping(value = "/add", method = { RequestMethod.POST, RequestMethod.GET })
	public ApiCommonResultVo add(UserBank userBank, Model model) {
		
		try {
			userBankServer.addUserBank(userBank);
			List<UserBank> list = userBankServer.queryAll(userBank);
		    return new ApiCommonResultVo(0, "操作成功", list );
		} catch (Exception e) {
			LOG.info("添加银行卡信息接口异常 ：" + e.getMessage());
			return new ApiCommonResultVo(-2, "系统异常", "");
		}
		
	}

	
	
	/**
	 * 函数功能说明 ： 修改银行卡信息
	 *
	 * @参数： @return
	 * @return String
	 * @throws
	 */
	@RequestMapping(value = "/update", method = { RequestMethod.POST, RequestMethod.GET })
	public ApiCommonResultVo update(UserBank userBank, Model model) {
		
		try {
			userBankServer.updateUserBank(userBank);
			List<UserBank> list = userBankServer.queryAll(userBank);
		    return new ApiCommonResultVo(0, "操作成功", list );
		} catch (Exception e) {
			LOG.info("修改银行卡信息接口异常 ：" + e.getMessage());
			return new ApiCommonResultVo(-2, "系统异常", "");
		}
		
		
	}

	/**
	 * 函数功能说明 ： 删除一个银行卡
	 *
	 * @参数： @return
	 * @return String
	 * @throws
	 */
	@RequestMapping(value = "/delOne", method = { RequestMethod.POST, RequestMethod.GET })
	public ApiCommonResultVo delOne(UserBank userBank, Model model) {
		
		try {
			userBankServer.delOneUserBank(userBank); 
			List<UserBank> list = userBankServer.queryAll(userBank);
		    return new ApiCommonResultVo(0, "操作成功", list );
		} catch (Exception e) {
			LOG.info("删除一个银行卡接口异常 ：" + e.getMessage());
			return new ApiCommonResultVo(-2, "系统异常", "");
		}
		
	}

	/**
	 * 函数功能说明 ： 删除多条银行卡
	 *
	 * @参数： @return
	 * @return String
	 * @throws
	 */
	@RequestMapping(value = "/delAll", method = { RequestMethod.POST, RequestMethod.GET })
	public ApiCommonResultVo delAll(String[]  ids , Model model) {
		
		try {
			List<UserBank> list = new ArrayList<>() ;
			for(int i=0 ; i < ids.length ; i ++ ){
				UserBank userBank = new UserBank() ;
				userBank.setId(ids[i]);
				list.add(userBank) ;
			}
			userBankServer.delAllUserBank(list);
		    return new ApiCommonResultVo(0, "操作成功", "" );
		} catch (Exception e) {
			LOG.info("删除多条银行卡接口异常 ：" + e.getMessage());
			return new ApiCommonResultVo(-2, "系统异常", "");
		}
		
		
	}
	

	/**
	 * 函数功能说明 ： 获取多张银行卡
	 *
	 * @参数： @return
	 * @return String
	 * @throws
	 */
	@RequestMapping(value = "/queryAll", method = { RequestMethod.POST, RequestMethod.GET })
	public ApiCommonResultVo queryAll(UserBank userBank, Model model) {
		
		try {
			List<UserBank> list = userBankServer.queryAll(userBank);
		    return new ApiCommonResultVo(0, "操作成功", list ); 
		} catch (Exception e) {
			LOG.info("获取多张银行卡接口异常 ：" + e.getMessage());
			return new ApiCommonResultVo(-2, "系统异常", "");
		}
		
	}
	
	

}
